<template>
	<view class="purchase-list"  customStyle="padding: 32rpx;">
		
		<view class="">
		 
		</view>
		<scroll-view v-if="goodsList.length >= 1" class="purchase-body" scroll-y="true" @scrolltolower="scrolltolower" @scrolltoupper="scrolltoupper" @scroll="scroll" @touchstart="touchstart" @touchend="touchend">
			<!-- <my-unit v-for="(item,index) in goodsList" :key="index" :info="item"></my-unit> -->
			<u-row v-for="(item,index) in  goodsList"   :key="index" customStyle="margin: 16rpx 0;" @click="cargo(item)">
				<u-col span="3">
			
					<u--image :showLoading="true" :src="item.picture" width='120rpx' height='120rpx'></u--image>
				</u-col>
				<u-col span="9">
					<u-row>
						 
						<u--text :text="item.goods_name || '未设置'" size='20' color='#BF3F3F' bold></u--text>
					</u-row>
					<u-row>
						<u-col span="6"> 
							<u--text :text="item.buy_number + item.unit" color='#3FBF7F'></u--text>
						</u-col>
						<u-col span="6">
							<u--text :text="item.expiration_date > new Date().getTime()?'未过期':'已过期'" color='#BCBCBC'>
							</u--text>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="2">
							<u--text text="录入:" size='12'></u--text>
			
						</u-col>
						<u-col span="4">
							<u--text mode="date" :text="item.add_time" size='12'></u--text>
			
						</u-col>
						<!-- <u-col span="4">
							<u--text text="有效: 360天" size='12'></u--text>
						</u-col> -->
						<u-col span="2">
							<u--text text="临期:" size='12'></u--text>
			
						</u-col>
						<u-col span="3">
							<u--text :text="item.temporary?'是':'未设置'||'未设置'" size='12'></u--text>
			
						</u-col>
					</u-row>
					<u-row>
						<u-col span="2">
							<u--text text="下架:" size='12'></u--text>
						</u-col>
						<u-col span="3">
							<u--text :text="item.status?'已下架':'未设置'||'未设置'" size='12'></u--text>
						</u-col>
						<u-col span="2" offset="1">	
			
							<u--text text="过:" size='12'></u--text>
						</u-col>
						<u-col span="4">
							<u--text mode="date" :text="Number(item.expiration_date)" size='12'></u--text>
						</u-col>
						 
					</u-row>
				</u-col>
			</u-row>
		</scroll-view>
		<u-empty
				v-else
		        mode="data"
		        icon="/static/icon/car.png"
		>
		</u-empty>

		<my-loading></my-loading>
	</view>
</template>

<script>
	var that
	import fyDropdown from '@/components/fy-dropdown/fy-dropdown.vue'
	import fyDropdownItem from '@/components/fy-dropdown/fy-dropdown.vue'
	import myUnit from '@/components/myUnits/purchaseUnit/unit.vue'
	import myPull from '@/static/js/myPull.js'
	import myLoading from '@/components/myLoading/myLoading.vue'
	var ERGoodsScan = require('../../../service/ERGoodsScan'),mERGoodsScan
	export default {
		components:{myUnit,myLoading,fyDropdown,fyDropdownItem},
		data() {
			return {
				goodsList:[],
				value1: 1,
				value2: 2, 
				searchName:''
			}
		},
		onLoad(e) {
			that = this
			console.log(e)
			mERGoodsScan = new ERGoodsScan(this.mNetTool)
			if(e){
				this.searchName = e.name  
				if(e.name  ){
					this.getShopListByname(e.name)
				}
				if(e.codeBar){
					this.getShopListByCode(e.codeBar)
				}
			}
			
		},
		mounted() {
			let userInfo = uni.getStorageSync('userInfo')
			if(!userInfo){
				uni.$u.toast('请先登录')
				return
			}
			let goodShopIds =  uni.getStorageSync('goodShopIds')
			let viewShopListItem =  uni.getStorageSync('viewShopListItem')
			let shopList =  uni.getStorageSync('shopList')
		  
			// let info = {
			// 	goods_name:this.searchName,
			// 	own_store_id:viewShopListItem.id,
			// }
			// mERGoodsScan.list(info,res => {
			// 	console.log('列表',res)
			// 	this.goodsList = res.rows
			// })
			
			
		},
		methods: {
			getShopListByCode(c){
				 
				if(shopId){
					this.mNetTool.getAjaxUrlValueBackground('capi/V2/ERGoodsManage/erGoodsManage/list',
						{
							bar_code:c,
							own_store_id:shopId
							},res =>{
						console.log(res)
						that.goodsList = res.rows
					  
					})
				}
				
			},
				getShopListByname(name){
					let shopId = uni.getStorageSync('shopId')
					if(shopId){
						this.mNetTool.getAjaxUrlValueBackground('capi/V2/ERGoodsManage/erGoodsManage/list',
							{
								goods_name:name,
								own_store_id:shopId
								},res =>{
							console.log(res)
							that.goodsList = res.rows
						  
						})
					}
					
				},
				openDropdown(index) {
					// 展开某个下来菜单时，先关闭原来的其他菜单的高亮
					// 同时内部会自动给当前展开项进行高亮
					this.$refs.uDropdown.highlight();
				},
				closeDropdown(index) {
					// 关闭的时候，给当前项加上高亮
					// 当然，您也可以通过监听dropdown-item的@change事件进行处理
					this.$refs.uDropdown.highlight(index);
				},
				change() {
					// 更多的细节，如有需要请自行根据业务逻辑进行处理
					// this.$refs.uDropdown.highlight(xxx);
				},
			 handlerColumnChange(e) {
			            if (e.cancel) return;
			
			            this.columnOptions.forEach(item=>{
			                item.default = e.data[item.key];
			            })
			        },
			        handlerTypeChange(e) {
			            console.log(e);
			        },
				/**
				 * @name 获取列表
				 */
				getList(page,done){
					uni.$u.toast(`获取第${page}页数据`)
					 console.log(`获取第${page}页数据`);
					 done([1])
				},
				
				/**
				 * @name 触底加载
				 */
				scrolltolower(event){
					this.getList(this.page,this.__pulldone)
				},
				
				scroll(e){
					// 重新设置pulldown
					this.setPullDown(e.detail.scrollTop<10)
				},
				
				scrolltoupper(){
					
				},
				
				
				/**
				 * @name 改变tab
				 * @param val 索引
				 */
				tapChange(val){
					this.initIndex=val
				}
			},
			mixins:[myPull({})],
			
		
	}
</script>

<style lang="scss">
	.purchase-list {
		background-color: #f5f5f5;
		height: 100%;
		overflow: hidden;
		
		.purchase-body{
			height: calc(100% - 88upx);
			overflow: auto
		}
	}
</style>
